package com;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.util.Assert;

import java.io.*;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author yuhang
 * @desc
 * @since 2022/4/28
 */
public class Fenxi {

    public static String httpPost(String url, String filePath) throws Exception {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        post.setHeader("X-TOKEN",
                "b546dcecf7942a1fde80f90815fbb4bda640e8d251f4202c9cc2cabb42da833754081de5299bfbbaec53a51bf2a9a994");
        post.setHeader("X-USER-ID", "709035");
        MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
        File file = new File(filePath);
        //当设置了setSocketTimeout参数后，以下代码上传PDF不能成功，将setSocketTimeout参数去掉后此可以上传成功。上传图片则没有个限制
        multipartEntityBuilder.addBinaryBody("file", file);
        HttpEntity httpEntity = multipartEntityBuilder.build();
        post.setEntity(httpEntity);
        CloseableHttpResponse httpResponse = client.execute(post);
        HttpEntity responseEntity = httpResponse.getEntity();
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode == 200) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
            StringBuffer buffer = new StringBuffer();
            String str = "";
            while ((str = reader.readLine()) != null) {
                buffer.append(str);
            }

            System.out.println(buffer.toString());
        }
        return null;
    }

    public static void main(String[] args) throws Exception {


//        System.out.println(httpPost("http://localhost:8316/api/b2/orders/import?platform=JD","D:/a.xlsx"));

             List<Integer> as = new ArrayList<>();
             for(int i=0;i<11;i++){

                 as.add(i);
             }

        System.out.println(as.subList(0,10));

        List<Integer> bas = new ArrayList<>();
        for(int i=10;i<20;i++){

            bas.add(i);
        }

        as = bas;

        bas.add(90);

        System.out.println(bas);
        System.out.println(as);
    }


}
